package route

import (
	"github.com/gin-gonic/gin"
	"shoping.zozoo.net/controllers"
	"shoping.zozoo.net/dao"
	"shoping.zozoo.net/middleware"
	"shoping.zozoo.net/service"
	"shoping.zozoo.net/tool"
)

func InitRouter(c *gin.Engine)  {

	//产品模块
	productGroup := c.Group("/product",middleware.JWTAuth())
	{
		d := dao.NewProductDao(tool.DbEngine)
		s := service.NewProductService(d)
		productController := controllers.NewProductController(s)
		productGroup.GET("/detail/:id",productController.Get)
		productGroup.GET("/list",productController.List)
		productGroup.POST("/insert",productController.Insert)
		productGroup.POST("/del/:id",productController.Del)
		productGroup.POST("/seckill",productController.Seckill)
	}

	//订单模块
	orderGroup := c.Group("/order")
	{
		d := dao.NewOrderDao(tool.DbEngine)
		s := service.NewOrderService(d)
		orderController := controllers.NewOrderController(s)

		//获取订单列表
		orderGroup.GET("/list",orderController.List)
		orderGroup.POST("/insert",orderController.Insert)
		orderGroup.DELETE("/del/:id",orderController.Delete)
		orderGroup.GET("/get/:id",orderController.Get)
	}

	//用户模块
	userGroup := c.Group("/user")
	{
		o := dao.NewUserDao(tool.DbEngine)
		s := service.NewUserService(o)
		userController := controllers.NewUserController(s)
		userGroup.POST("/register",userController.Register)
		userGroup.POST("/login",userController.Login)
	}
}
